package com.jpl.demo.mobility.ui.view.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.vaadin.addon.touchkit.ui.NavigationBar;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class BusTimingToolBar extends NavigationBar {

	private static final long serialVersionUID = 1L;

	static Resource refreshIcon = new ThemeResource("graphics/reload-icon.png");
	private Button refresh;

	public BusTimingToolBar() {
		this.refresh = new Button();
		this.refresh.setIcon(refreshIcon);
		this.refresh.addStyleName("no-decoration");

		setRightComponent(this.refresh);

		final SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm");
		setCaption("Updated " + formatter.format(Calendar.getInstance().getTime()));

		this.refresh.addListener(new Button.ClickListener() {

			private static final long serialVersionUID = 1L;

			@Override
			public void buttonClick(ClickEvent event) {
				setCaption("Updated " + formatter.format(Calendar.getInstance().getTime()));
			}
		});
	}

	/**
	 * Complete the refresh button click listener.
	 * 
	 * @param listener the Listener to be added.
	 */
	public void addRefreshButtonListener(ClickListener listener) {
		this.refresh.addListener(listener);
	}

}
